/*RESULTS USING ALTERNATIVE MEASURES OF IDEOLOGY

This code replicates the matching analyses using alternative ideology measures 


The primary dataset for these analyses is the "Combined105-116_HRC" dataset. 

The secondary data used for these analyses contains the alternative measures of ideology. That dataset is 
"aip_cd_ideology_v2022a.dta"

The Ideology dataset has observations only for the folowing congresses: 111, 114, 116, 117 and 118
The HRC dataset covers from 105-116. The overlap is only for three Congresses: 111, 114 & 116

Coarsening Choices for nominate_d1 I have coarsened the data into four bins based on t25th, 50th and 75th percentile for each Cngress. 

*/



*Merging the HRC data with the AIPS dataset
sort cd_fips congress

merge m:1 cd_fips congress using "aip_cd_ideology_v2022a.dta"

**Analysis only of Democratic legislators and drops any legislators without
**known LGB status

drop if  democrat==0
drop if LGBLegislator==.


**********************Results using the MRP Ideology Measure ****************************


**111th Congress, adjust matching variables based on data availability
table LGBLegislator if congress==111 
imb  nominate_d1   urban mrp_ideology LGBHousehold  if congress==111, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) mrp_ideology if congress==111 , tr(LGBLegislator)
gen T111=LGBLegislator
label variable T111 "111th Congress"
eststo cong111:reg hrc T111 nominate_d1 LGBHousehold   urban mrp_ideology [iweight=cem_weights] if congress==111, robust
outreg2 using  H1Dems_AltID.xls, replace ///
label ctitle("111th Congress, MRP ") 
*rename (mrp*) (_111_mrp*)
///

**114th Congress, adjust matching variables based on data availability
table LGBLegislator if congress==114 & district>0
imb nominate_d1  urban mrp_ideology LGBHousehold   if congress==114, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) mrp_ideology  if congress==114, tr(LGBLegislator)
gen T114=LGBLegislator
label variable T114 "114th Congress"
eststo cong114: reg hrc T114 nominate_d1  LGBHousehold mrp_ideology urban   [iweight=cem_weights] if congress==114, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("114th Congress, MRP ") 
*rename (mrp*) (_114_mrp*)
///


**116th Congress
table LGBLegislator if congress==116 & district>0
imb nominate_d1   urban mrp_ideology LGBHousehold   if congress==116 & district>0, tr(LGBLegislator)
cem nominate_d1(-0.37 -.16 0.48) LGBHousehold  urban mrp_ideology   if congress==116 & district>0, tr(LGBLegislator) 
label variable LGBLegislator cong116
gen T116=LGBLegislator
label variable T116 "116th Congress"
eststo cong116: reg hrc T116 nominate_d1 LGBHousehold mrp_ideology urban   [iweight=cem_weights] if congress==116, robust
estimates store cong116
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("116th Congress, MRP ")
*rename (mrp*) (_116_mrp*)
///


**Pooled Analysis from the three with Warshaw data
quietly tabulate congress, generate(new_congress)
table LGBLegislator if congress==111|congress==114|congress==116
imb nominate_d1   urban mrp_ideology LGBHousehold if congress==111|congress==114|congress==116, tr(LGBLegislator)
cem nominate_d1(-0.36 0.16 0.43)   urban mrp_ideology LGBHousehold if  congress==111|congress==114|congress==116, tr(LGBLegislator) 
gen TAll=LGBLegislator
label variable TAll "All Congresses"
eststo AllCongress: reg hrc TAll nominate_d1 mrp_ideology urban LGBHousehold  i.congress [iweight=cem_weights] if congress==111|congress==114|congress==116, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("All Congresses, MRP ") 
*rename (mrp*) (all_cong_mrp*)
///


coefplot cong111  cong114  cong116 AllCongress, keep(T111 T114  T116 TAll) scheme(s1mono) xline(0) level(90) legend(off) xtitle(Estimates for Democratic LGB Legislators -- MRP Ideology)



**********************Results using the Self Ideology Variable****************************


clear
use "Combined105-116_HRC.dta"


 */Coarsening Choices for nominate_d1 I have coarsened the data into four bins based on t25th, 50th and 75th percentile for each Cngress. 

*/


**merging datasets

/* the Ideology dataset has observations only for the folowing congresses: 111, 
114, 116, 117 and 118
The HRC dataset covers from 105-116. The overlap is only for three Congresses: 
111, 114 & 116*/


drop if district==0

sort cd_fips congress



merge m:1 cd_fips congress using "aip_cd_ideology_v2022a.dta"

**Analysis only of Democratic legislators and drops any legislators without
**known LGB status

drop if  democrat==0
drop if LGBLegislator==.

**111th Congress, adjust matching variables based on data availability
**this comparison uses the Self Ideology measure
table LGBLegislator if congress==111 
imb  nominate_d1   urban self_ideology LGBHousehold  if congress==111, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) self_ideology if congress==111 , tr(LGBLegislator)
gen T111=LGBLegislator
label variable T111 "111th Congress"
eststo cong111:reg hrc T111 nominate_d1 LGBHousehold   urban self_ideology [iweight=cem_weights] if congress==111, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("111th Congress, Self Ideology ") 
*rename (self*) (_111_self*)
///

**114th Congress, adjust matching variables based on data availability
table LGBLegislator if congress==114 & district>0
imb nominate_d1  urban self_ideology LGBHousehold   if congress==114, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) self_ideology  if congress==114, tr(LGBLegislator)
gen T114=LGBLegislator
label variable T114 "114th Congress"
eststo cong114: reg hrc T114 nominate_d1  LGBHousehold self_ideology urban   [iweight=cem_weights] if congress==114, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("114th Congress, Self Ideology ") 
*rename (self*) (_114_self*)
///


**116th Congress
table LGBLegislator if congress==116 & district>0
imb nominate_d1   urban self_ideology LGBHousehold   if congress==116 & district>0, tr(LGBLegislator)
cem nominate_d1(-0.37 -.16 0.48) LGBHousehold  urban self_ideology   if congress==116 & district>0, tr(LGBLegislator) 
label variable LGBLegislator cong116
gen T116=LGBLegislator
label variable T116 "116th Congress"
eststo cong116: reg hrc T116 nominate_d1 LGBHousehold self_ideology urban   [iweight=cem_weights] if congress==116, robust
estimates store cong116
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("116th Congress, Self Ideology ")
*rename (self*) (_116_self*)
///


**Pooled Analysis from the three with Self IDeology measre data
quietly tabulate congress, generate(new_congress)
table LGBLegislator if congress==111|congress==114|congress==116
imb nominate_d1   urban self_ideology LGBHousehold if congress==111|congress==114|congress==116, tr(LGBLegislator)
cem nominate_d1(-0.36 0.16 0.43)   urban self_ideology LGBHousehold if  congress==111|congress==114|congress==116, tr(LGBLegislator) 
gen TAll=LGBLegislator
label variable TAll "All Congresses"
eststo AllCongress: reg hrc TAll nominate_d1 self_ideology urban LGBHousehold  i.congress [iweight=cem_weights] if congress==111|congress==114|congress==116, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("All Congresses, Self Ideology ") 
*rename (self*) (all_cong_self*)
///

coefplot cong111  cong114  cong116 AllCongress, keep(T111 T114  T116 TAll) scheme(s1mono) xline(0) level(90) legend(off) xtitle(Estimates for Democratic LGB Legislators -- Self Ideology)



**********************Results using the IRT Ideology Variable****************************

**Analysis Using the Warshaw Data
clear

use "Combined105-116_HRC.dta", replace



 */Coarsening Choices for nominate_d1 I have coarsened the data into four bins based on t25th, 50th and 75th percentile for each Cngress. 

*/


**merging datasets

/* the Ideology dataset has observations only for the folowing congresses: 111, 
114, 116, 117 and 118
The HRC dataset covers from 105-116. The overlap is only for three Congresses: 
111, 114 & 116*/


drop if district==0

sort cd_fips congress



merge m:1 cd_fips congress using "aip_cd_ideology_v2022a.dta"

**Analysis only of Democratic legislators and drops any legislators without
**known LGB status

drop if  democrat==0
drop if LGBLegislator==.

**111th Congress, adjust matching variables based on data availability
**this comparison uses the Self Ideology measure
table LGBLegislator if congress==111 
imb  nominate_d1   urban irt_ideology_unweighted LGBHousehold  if congress==111, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) irt_ideology_unweighted if congress==111 , tr(LGBLegislator)
gen T111=LGBLegislator
label variable T111 "111th Congress"
eststo cong111:reg hrc T111 nominate_d1 LGBHousehold   urban irt_ideology_unweighted [iweight=cem_weights] if congress==111, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("111th Congress, IRT ") 
*rename (self*) (_111_self*)
///

**114th Congress, adjust matching variables based on data availability
table LGBLegislator if congress==114 & district>0
imb nominate_d1  urban irt_ideology_unweighted LGBHousehold   if congress==114, tr(LGBLegislator)
cem nominate_d1(-0.37 .28 0.51) LGBHousehold urban(40 80) irt_ideology_unweighted  if congress==114, tr(LGBLegislator)
gen T114=LGBLegislator
label variable T114 "114th Congress"
eststo cong114: reg hrc T114 nominate_d1  LGBHousehold irt_ideology_unweighted urban   [iweight=cem_weights] if congress==114, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("114th Congress, IRT ") 
*rename (self*) (_114_self*)
///


**116th Congress
table LGBLegislator if congress==116 & district>0
imb nominate_d1   urban irt_ideology_unweighted LGBHousehold   if congress==116 & district>0, tr(LGBLegislator)
cem nominate_d1(-0.37 -.16 0.48) LGBHousehold  urban irt_ideology_unweighted   if congress==116 & district>0, tr(LGBLegislator) 
label variable LGBLegislator cong116
gen T116=LGBLegislator
label variable T116 "116th Congress"
eststo cong116: reg hrc T116 nominate_d1 LGBHousehold irt_ideology_unweighted urban   [iweight=cem_weights] if congress==116, robust
estimates store cong116
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("116th Congress, IRT ")
*rename (self*) (_116_self*)
///


**Pooled Analysis from the three with Self IDeology measre data
quietly tabulate congress, generate(new_congress)
table LGBLegislator if congress==111|congress==114|congress==116
imb nominate_d1   urban irt_ideology_unweighted LGBHousehold if congress==111|congress==114|congress==116, tr(LGBLegislator)
cem nominate_d1(-0.36 0.16 0.43)   urban irt_ideology_unweighted LGBHousehold if  congress==111|congress==114|congress==116, tr(LGBLegislator) 
gen TAll=LGBLegislator
label variable TAll "All Congresses"
eststo AllCongress: reg hrc TAll nominate_d1 irt_ideology_unweighted urban LGBHousehold  i.congress [iweight=cem_weights] if congress==111|congress==114|congress==116, robust
outreg2 using  H1Dems_AltID.xls, append ///
label ctitle("All Congresses, IRT ") 
*rename (self*) (all_cong_self*)
///

coefplot cong111  cong114  cong116 AllCongress, keep(T111 T114  T116 TAll) scheme(s1mono) xline(0) level(90) legend(off) xtitle(Estimates for Democratic LGB Legislators -- IRT Ideology)
